<?php
class geo
{	function getSpaceBetweenPositions($lat1, $lat2, $lon1, $lon2)
	{		$lat1 *= M_PI / 180;
		$lat2 *= M_PI / 180;
		$lon1 *= M_PI / 180;
		$lon2 *= M_PI / 180;

		$d_lon = $lon1 - $lon2;

		$slat1 = sin($lat1);
		$slat2 = sin($lat2);
		$clat1 = cos($lat1);
		$clat2 = cos($lat2);
		$sdelt = sin($d_lon);
		$cdelt = cos($d_lon);

		$y = pow($clat2 * $sdelt, 2) + pow($clat1 * $slat2 - $slat1 * $clat2 * $cdelt, 2);
		$x = $slat1 * $slat2 + $clat1 * $clat2 * $cdelt;

		return atan2(sqrt($y), $x) * 6372795;	}
	function getPositionByAddress($city, $street='', $building='')
	{		$position=false;		$address=array($city, $street, $building);
		$address=implode(', ', $address);		$params = array(
		    'geocode' => $address, // адрес
		    'format'  => 'json',                          // формат ответа
		    'results' => 1,                               // количество выводимых результатов
		    'key'     => 'AC40TVMBAAAAAgqCFwIAz-vPiDwhb8fUBTHoPFOAJd6CVTEAAAAAAAAAAADJ_GnUXHDcFDpPbWU9frL9eMsrdg==',                           // ваш api key
		);
		$response = json_decode(@file_get_contents('http://geocode-maps.yandex.ru/1.x/?' . http_build_query($params, '', '&')));

		if($response->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found > 0)
		{
		    $position=$response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos;
		}
		return $position;	}}
?>